import { watch } from 'rollup';
import { getRollupConfigs } from './build.base.js';

async function dev() {
  const configs = await getRollupConfigs();
  for (const name in configs) {
    const config = configs[name];
    const watcher = watch(
      config.output.map((o) => {
        return {
          input: config.input,
          plugins: config.plugins,
          external: config.external,
          output: o,
          watch: config.watch,
        };
      }),
    );

    watcher.on('event', (event) => {
      switch (event.code) {
        case 'START':
          console.log(`开始监听：${name}`);
          break;
        case 'BUILD_START':
          console.log(`${name} 构建中`);
          break;
        case 'BUILD_END':
          console.log(`${name} 构建完成`);
          break;
        case 'ERROR':
          console.log(`${name} 构建失败`);
          break;
        default:
          break;
      }
    });
  }
}

dev();
